﻿using FarmSmartSleep.Common.Domain.PM.select;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;

namespace FarmSmartSleep.Organ.API.Application.ProductionManagement.MotherHybridizationCommands
{
    public class EstrusTypeSearchHander : IRequestHandler<EstrusTypeSearchCommand, ResultT<EstrusType>>
    {

        private readonly ILogger<EstrusTypeSearchHander> logger;
        private readonly IBaseRepository<EstrusType> baseRepository;

        public EstrusTypeSearchHander(ILogger<EstrusTypeSearchHander> logger, IBaseRepository<EstrusType> baseRepository)
        {
            this.logger = logger;
            this.baseRepository = baseRepository;
        }
        /// <summary>
        /// 获取种母发情类型
        /// </summary>
        /// <param name="request">获取种母发情类型请求对象</param>
        /// <param name="cancellationToken">多线程之取消令牌</param>
        /// <returns>返回种母发情类型数据集合</returns>
        public async Task<ResultT<EstrusType>> Handle(EstrusTypeSearchCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var result = new ResultT<EstrusType>();
                result.Data =  baseRepository.GetAll().ToList();
                logger.LogInformation("获取种母发情类型方法调用成功");
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("获取种母发情类型方法调用出错" + ex);
                throw;
            }
        }
    }
}
